#coding:utf-8

# Create your views here.
from django.shortcuts import render
from django.shortcuts import redirect
def login(request):
    if request.method == 'POST':
        input_email = request.POST['email']
        input_pwd = request.POST['pwd']
        if input_email == 'user1@qq.com' and input_pwd == '123':
            return redirect("/index/")
        else:
            return render(request,"login.html",{"status":"用户名密码错误"})
    return render(request,'login.html')

def index(request):
    #从数据库中获取数据，并和html渲染
    from app01 import models
    #添加数据
    # if request.method=='POST':
    #     input_em = request.POST['em']
    #     input_pw = request.POST['pw']
    #     models.UserInfo.objects.create(email=input_em,pwd=input_pw)
    #删除数据
    # if request.method=='POST':
    #     input_email = request.POST['email_del']
    #     models.UserInfo.objects.filter(email=input_email).delete()
    #更新数据
    if request.method=='POST':
        input_em = request.POST['email_update']
        input_pw = request.POST['pwd_update']
        models.UserInfo.objects.filter(email=input_em).update(pwd=input_pw)
    #获取表中所有数据
    user_info_list = models.UserInfo.objects.all()
    return render(request,'index.html',{"user_info_list":user_info_list,})